package com.lgs.demo.ui;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.lgs.demo.R;
import com.lgs.demo.base.BaseActivity;
import com.lgs.demo.bean.PackData;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {

    private List<Fragment> fragmentList;

    @BindView(R.id.main_radioGroup)
    RadioGroup mBottomMenuRg;
    @BindView(R.id.main_patrolRb)
    RadioButton mPatrolRb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        initFragment();
        //设置RadioGroup的监听
        setOnListener();
//                mBottomMenuRg.check(R.id.main_patrolRb);    //第一次启动时生命周期执行两次创建两次对象,如果没有把fragment放在集合中时
        mPatrolRb.setChecked(true); //生命周期执行一次
    }

    private void initFragment() {
        fragmentList = new ArrayList<>();
        fragmentList.add(HomeFragment.getInstance());
        fragmentList.add(ConnectFragment.newInstance());
        fragmentList.add(FriendsFragment.newInstance());
        fragmentList.add(MyFragment.newInstance());
    }

    private void setOnListener() {

        mBottomMenuRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId) {
                    case R.id.main_patrolRb:
                        changeFragment(mCurrentFragment, fragmentList.get(0));
                        break;
                    case R.id.main_pondRb:
                        changeFragment(mCurrentFragment, fragmentList.get(1));
                        break;
                    case R.id.main_equipmentRb:
                        changeFragment(mCurrentFragment, fragmentList.get(2));
                        break;
                    case R.id.main_settingRb:
                        changeFragment(mCurrentFragment, fragmentList.get(3));
                        break;
                }
            }
        });
    }

    private OnPassParams mPass;

    public OnPassParams getmPass() {
        return mPass;
    }

    public void setmPass(OnPassParams mPass) {
        this.mPass = mPass;
    }

    public interface OnPassParams {
        void setData(PackData data);
    }

    public void callback(OnPassParams pass) {
        this.mPass = pass;
    }
}
